package cn.aixuxi.notebank.service.impl;

import cn.aixuxi.notebank.entity.RoleEntity;
import cn.aixuxi.notebank.entity.RolePermissionEntity;
import cn.aixuxi.notebank.mapper.RoleMapper;
import cn.aixuxi.notebank.mapper.RolePermissionMapper;
import cn.aixuxi.notebank.service.IRolePermissionService;
import cn.aixuxi.notebank.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 类描述 角色服务实现
 *
 * @author ruozhuliufeng
 * @version 1.0
 * @date 2020/12/18 11:29
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermissionEntity> implements IRolePermissionService {


    /**
     * 功能描述: 判断角色与权限是否已经添加过
     *
     * @param entity 1
     * @return : true-添加 false-未添加
     * @author : ruozhuliufeng
     * @date : 2020/12/24 16:51
     */
    @Override
    public boolean isExist(RolePermissionEntity entity) {
        QueryWrapper<RolePermissionEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", entity.getRoleId());
        queryWrapper.eq("permission_id", entity.getPermissionId());
        int count = this.count(queryWrapper);
        return count == 1;
    }
}
